﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace NumericalMethod
{

    public struct DPoint
    {
        public double x, y;

        public DPoint(double p1, double p2)
        {
            x = p1;
            y = p2;
        }
    }

    public partial class graphFX : UserControl
    {
         private GraphPane m_graphPane;
         public string PlotTitle;
         public PointPairList PointsList;
         public PointPairList BackPointsList;

        public graphFX()
        {
            InitializeComponent();
            PointsList = new PointPairList();
            BackPointsList = new PointPairList();
            m_graphPane = zg1.GraphPane;

            //this.Controls.Add(Px);
            //Px.Size = this.Size;
        }

        private void graphFX_Load(object sender, EventArgs e)
        {

        }
        public void generateGraph(int[] x, int[] y)
        {
            List<DPoint> pin = new List<DPoint>();
            for (int i = 0; i < x.Length; i++)
                pin.Add(new DPoint(x[i], y[i])); 
            generateGraph(pin);
        }
        /// <summary>
        /// Generate the graph base on List of point
        /// </summary>
        /// <param name="points">List of point</param>
        public void generateGraph( List<DPoint> points)
        {
        }
        public void CreateLineGraph()
        {
           //clear if anything exists.            
           m_graphPane.CurveList.Clear();

           // Set the titles and axis labels
           //SetLineBarTitleAndAxisDetails( ref _graphTitle, ref _xTitle, ref _yTitle );
           m_graphPane.Title.Text = PlotTitle;
           m_graphPane.XAxis.Title.Text = "x";
           m_graphPane.YAxis.Title.Text = "f(x)";

           //m_graphPane.LineType = LineType.Stack;
           m_graphPane.AddCurve(PlotTitle, PointsList, Color.Blue, SymbolType.Star);

           // Calculate the Axis Scale Ranges
           zg1.AxisChange();
           zg1.Invalidate();
        }
        public void AddLineOnly()
        {
           // Set the titles and axis labels
           //SetLineBarTitleAndAxisDetails( ref _graphTitle, ref _xTitle, ref _yTitle );
           m_graphPane.Title.Text = PlotTitle;
           m_graphPane.XAxis.Title.Text = "x";
           m_graphPane.YAxis.Title.Text = "f(x)";

           //m_graphPane.LineType = LineType.Stack;
           m_graphPane.AddCurve(PlotTitle, PointsList, Color.Blue, SymbolType.None);

           // Calculate the Axis Scale Ranges
           zg1.AxisChange();
           zg1.Invalidate();
        }
        public void AddScatterPlot()
        {
           //clear if anything exists.            
           m_graphPane.CurveList.Clear();

           // Set the titles and axis labels
           //SetLineBarTitleAndAxisDetails( ref _graphTitle, ref _xTitle, ref _yTitle );
           m_graphPane.Title.Text = PlotTitle;
           m_graphPane.XAxis.Title.Text = "x";
           m_graphPane.YAxis.Title.Text = "f(x)";

           // Generate a blue curve with Star symbols
           LineItem invisible = m_graphPane.AddCurve(PlotTitle, BackPointsList, Color.Green, SymbolType.Star);
           invisible.Line.IsVisible = false;

           // Calculate the Axis Scale Ranges
           zg1.AxisChange();
           zg1.Invalidate();
        }
    }
}
